package com.woniuxy.userassembly.service.impl;

import com.woniuxy.userassembly.model.User;
import com.woniuxy.userassembly.dao.UserMapper;
import com.woniuxy.userassembly.service.IUserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.val;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Liyfi
 * @since 2021-05-22
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IUserService {

    @Autowired
    private UserMapper mapper;

    @Override
    public void registerUser(User user) {
        mapper.insert(user);
    }

    @Override
    public User loginByUsername(String username, String password) {
        User user = mapper.loginByUsername(username, password);
        return user;
    }

    @Override
    public User checkOnlyTel(String tel) {
        User user = mapper.checkOnlyTel(tel);
        return user;
    }

    @Override
    public int updUser(User user) {
        int i = mapper.updUser(user.getUsername(),user.getPassword(),user.getAddr(),user.getHeadUrl(),user.getUserId());
        return i;
    }

    @Override
    public int increaseCredit(Integer credit, Integer userId) {
        int i = mapper.increaseCredit(credit, userId);
        return i;
    }

    @Override
    public int cutBackCredit(Integer credit, Integer userId) {
        int i = mapper.cutBackCredit(credit,userId);
        return i;
    }

    @Override
    public User selUser(Integer userId) {
        User user = mapper.selUser(userId);
        return user;
    }

    @Override
    public int changeLevel(Integer level,Integer userId) {
        int i = mapper.changeLevel(level, userId);
        return i;
    }

    @Override
    public int increaseGrowthValue(Integer growth, Integer userId) {
        int i = mapper.increaseGrowthValue(growth, userId);
        return i;
    }

    @Override
    public int addMoney(double balance, int userId) {
        int  i = mapper.addMoney(balance, userId);
        return i;
    }
}
